
window.onload = function () {
    document.getElementById("administrative").className = "add-nav-active";
    document.getElementById("meeting_room").className = "add_class";
    document.getElementById("meeting_management_ul").style.display = "inline-block";
    document.getElementById("jiantou2").className = "iconfont icon-jiantou-xia";
    document.getElementById("organizational_management_ul").style.display = "none";
    room_list()
};



function click_ul() {
    if (document.getElementById("jiantou").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou").className = "iconfont icon-jiantou-xia";
        document.getElementById("organizational_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou").className = "iconfont icon-jiantou-shang";
        document.getElementById("organizational_management_ul").style.display = "none";
    }
}

function click_ul1() {
    if (document.getElementById("jiantou1").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-xia";
        document.getElementById("gebruikersrol_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-shang";
        document.getElementById("gebruikersrol_ul").style.display = "none";
    }
}

function click_ul2() {
    if (document.getElementById("jiantou2").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-xia";
        document.getElementById("meeting_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-shang";
        document.getElementById("meeting_management_ul").style.display = "none";
    }
}

function click_ul3() {
    if (document.getElementById("jiantou3").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-xia";
        document.getElementById("issue_approval_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-shang";
        document.getElementById("issue_approval_ul").style.display = "none";
    }
}


// 获取cookies
function getCookie(objName) {//获取指定名称的cookie的值
    var arrStr = document.cookie.split("; ");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] === objName) {
            return decodeURI(temp[1]);
        }
    }
}



// 请求数据
function room_list(page) {
    page = page || 1;
    document.cookie = "page=" + page;
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/meeting_room.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send("page="+String(page));
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                create_table(JsonDate["count_num"], JsonDate["data"]);
                pagenum(JsonDate["count_num"], page);
            }
        }
    };
}



// 创建新闻表格
function create_table(count_num, json_data) {
    var t_table = document.getElementById("t_table");
    deltr();
    if (json_data.length === 0){
        document.getElementById("img-display").style.display = "inline-block";
    }else {
        document.getElementById("img-display").style.display = "none";
    }
    for (var i=0; i<json_data.length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");
        var td5 = document.createElement("td");var td6 = document.createElement("td");var td7 = document.createElement("td");var td8 = document.createElement("td");var td9 = document.createElement("td");var td10 = document.createElement("td");var td11 = document.createElement("td");
        td.innerHTML = "<input id='"+json_data[i]["id"]+"' class='check_box' type=\"checkbox\">";td.style.background="#f8f9fa";td.style.textAlign = "center";td.setAttribute( "onclick", "check_more_one_not("+json_data[i]["id"]+")");
        // td1.innerHTML = "<a href='detail.html?type=xinwen&id="+json_data[i]["id"]+"' target=\"_blank\">"+json_data[i]["car_model"]+"</a>";td1.title = json_data[i]["car_model"];td1.style.paddingLeft = "1%";
        // td1.innerHTML = "<a href='"+json_data[i]["img_path"]+"' target=\"_blank\">"+json_data[i]["car_model"]+"</a>";td1.title = json_data[i]["car_model"];td1.style.paddingLeft = "1%";
        td1.innerHTML = i+1;td2.title = i+1;td1.style.textAlign = "center";
        td2.innerHTML = json_data[i]["room_name"];td2.title = json_data[i]["room_name"];td2.style.textAlign = "center";
        td3.innerHTML = json_data[i]["capacity"];td3.title = json_data[i]["capacity"];td3.style.textAlign = "center";
        td4.innerHTML = json_data[i]["room_site"];td4.title = json_data[i]["room_site"];td4.style.textAlign = "center";
        td5.innerHTML = json_data[i]["room_configure"];td5.title = json_data[i]["room_configure"];td5.style.textAlign = "center";
        td6.innerHTML = json_data[i]["remark"];td6.title = json_data[i]["remark"];td6.style.textAlign = "center";
        td7.innerHTML = "<a target='_blank' href='modify_meetingroom.html?id="+json_data[i]["id"]+"' id='"+json_data[i]["id"]+"'>修改 </a> | <a href='#' id='"+json_data[i]["id"]+"' onclick='Confirm_delete2(this.id)' data-toggle=\"modal\" data-target=\".bd-example-modal-sm\"> 删除</a>";td7.style.textAlign = "center";
        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);
        tr.appendChild(td5);tr.appendChild(td6);tr.appendChild(td7);
        t_table.appendChild(tr);
    }
}


// 删除公告列表
function deltr(){
    var tb = document.getElementById('t_table');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}


// 分页
function pagenum(dataTotals, page) {
    page = page || 1;
    dataTotals = dataTotals || 0;
    new myPagination({
        id: 'pagination',
        curPage: page, //初始页码
        pageAmount: 20,  //每页多少条
        dataTotal: dataTotals, //总共多少条数据
        pageTotal:  Math.ceil(parseInt(dataTotals, 10)/20), //总页数
        pageSize: 5, //可选,分页个数
        showPageTotalFlag:true, //是否显示数据统计
        showSkipInputFlag:true, //是否支持跳转
        getPage: function (page) {
            station_list(page);
            document.getElementById("check_all").checked = false;
        }
    });
}



// 选择新闻并删除
function delete_news(ele_id) {
    document.getElementById("close-model2").click();
    var page = getCookie("page");
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/meeting_room.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send("page="+String(page)+"&delete_list="+String(ele_id));
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                create_table(JsonDate["count_num"], JsonDate["data"]);
                pagenum(JsonDate["count_num"], page);
            }
        }
    };
}



// 确认删除
function Confirm_delete2(ele_id) {
    document.getElementById("countersign").setAttribute("onclick", "delete_news("+ele_id+")");
    var myArray = new Array();
    var check_box_list = document.getElementsByClassName("check_box");
    for (var t = 0; t < check_box_list.length; t++) {
        if (check_box_list[t].checked) {
            myArray.push(check_box_list[t].id)
        }
    }
    document.getElementById("Confirm-content").innerHTML = "<i style='color: #1E90FF;font-size: 50px;vertical-align:middle;' class=\"iconfont icon-jinggao-chucuo\"></i> <span>确认要删除这此会议室吗？</span>"
}
